package com.itianyu.blog.util;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.dao.DataAccessException;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Service;

import com.itianyu.blog.dao.beans.User;
import com.itianyu.blog.dao.interfaces.UserInterface;

/**
 * 获取管理用户验证信息
 * @author wumgji
 */
@Service
public class CustomUserDetailsService implements UserDetailsService {

	// Bean Interfaces
	@Autowired
	private UserInterface userInterface;

	@Override
	public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException, DataAccessException {

		User user = userInterface.findUser(username);
		if (user == null) {
			throw new UsernameNotFoundException("User '" + username + "' not found.");
		}
		return user;
	}

}
